package core.views;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
//import javax.swing.JButton;

import core.Runner;
import core.models.Person;
import core.models.Professions;
import core.models.Paces;
import core.models.Rations;

/**
 * Displays the main group creation and start up screen.
 *
 * @author 4c1a
 */
@SuppressWarnings("serial")
public class SetupPanel extends JPanel {
	private JTextField groupNameTextField;
	private JTextField person1NameTextField;
	private JTextField person2NameTextField;
	private JTextField person3NameTextField;
	private JTextField person4NameTextField;
	private JTextField person5NameTextField;
	private JLabel groupNameLabel;
	private JLabel person1NameLabel;
	private JLabel person2NameLabel;
	private JLabel person3NameLabel;
	private JLabel person4NameLabel;
	private JLabel person5NameLabel;
	private JLabel professionLabel;
	private JLabel paceLabel;
	private JLabel foodRationsLabel;
	private JComboBox professionComboBox;
	private JComboBox paceComboBox;
	private JComboBox foodRationsComboBox;
	private Runner runner;
//	private comboBoxListener listener;
	
	/**
	 * Brings up a screen that allows the player to set professions, rations, group member's names, and pace. 
	 * Also displays wagon capacity and amount of money. 
	 * 
	 * @param  runner The runner to be used by the panel.
	 */
	public SetupPanel(Runner runer) {
		this.runner=runer;
		setLayout(null);
//		listener = new comboBoxListener();

		
		groupNameLabel = new JLabel("Group Name:");
		groupNameLabel.setBounds(10, 11, 91, 14);
		add(groupNameLabel);
		
		groupNameTextField = new JTextField();
		groupNameTextField.setBounds(111, 8, 86, 20);
		add(groupNameTextField);
		groupNameTextField.setColumns(10);
		
		person1NameLabel = new JLabel("Person 1 Name:");
		person1NameLabel.setBounds(10, 54, 91, 14);
		add(person1NameLabel);
		
		person1NameTextField = new JTextField();
		person1NameTextField.setBounds(111, 51, 86, 20);
		person1NameTextField.setColumns(10);
		add(person1NameTextField);
		
		person2NameLabel = new JLabel("Person 2 Name:");
		person2NameLabel.setBounds(10, 82, 91, 14);
		add(person2NameLabel);
		
		person2NameTextField = new JTextField();
		person2NameTextField.setBounds(111, 79, 86, 20);
		person2NameTextField.setColumns(10);
		add(person2NameTextField);
		
		person3NameLabel = new JLabel("Person 3 Name:");
		person3NameLabel.setBounds(10, 110, 91, 14);
		add(person3NameLabel);
		
		person3NameTextField = new JTextField();
		person3NameTextField.setBounds(111, 107, 86, 20);
		person3NameTextField.setColumns(10);
		add(person3NameTextField);
		
		person4NameLabel = new JLabel("Person 4 Name:");
		person4NameLabel.setBounds(10, 138, 91, 14);
		add(person4NameLabel);
		
		person4NameTextField = new JTextField();
		person4NameTextField.setBounds(111, 135, 86, 20);
		person4NameTextField.setColumns(10);
		add(person4NameTextField);
		
		person5NameLabel = new JLabel("Person 5 Name:");
		person5NameLabel.setBounds(10, 163, 91, 14);
		add(person5NameLabel);
		
		person5NameTextField = new JTextField();
		person5NameTextField.setBounds(111, 160, 86, 20);
		person5NameTextField.setColumns(10);
		add(person5NameTextField);
		
		professionLabel = new JLabel("Profession:");
		professionLabel.setBounds(220, 11, 73, 14);
		add(professionLabel);
		
		professionComboBox = new JComboBox();
		professionComboBox.setBounds(309, 8, 94, 20);
		professionComboBox.setModel(new DefaultComboBoxModel(Professions.values()));
		add(professionComboBox);
		
		paceLabel = new JLabel("Pace:");
		paceLabel.setBounds(220, 54, 54, 14);
		add(paceLabel);
		
		paceComboBox = new JComboBox();
		paceComboBox.setBounds(309, 51, 94, 20);
		paceComboBox.setModel(new DefaultComboBoxModel(Paces.values()));
		add(paceComboBox);
//		paceComboBox.addActionListener(listener);
		
		foodRationsLabel = new JLabel("Food Rations:");
		foodRationsLabel.setBounds(220, 82, 79, 14);
		add(foodRationsLabel);
		
		foodRationsComboBox = new JComboBox();
		foodRationsComboBox.setBounds(309, 79, 94, 20);
		foodRationsComboBox.setModel(new DefaultComboBoxModel(Rations.values()));
		add(foodRationsComboBox);
	}
	
	/**
	 * Helper method for housekeeping
	 */
	public void update() {
		runner.getGroup().setName(groupNameTextField.getText());
		List<Person> peopleList = new ArrayList<Person>(); 
		Person p = new Person(person1NameTextField.getText());
		peopleList.add(p);
		p = new Person(person2NameTextField.getText());
		peopleList.add(p);
		p = new Person(person3NameTextField.getText());
		peopleList.add(p);
		p = new Person(person4NameTextField.getText());
		peopleList.add(p);
		p = new Person(person5NameTextField.getText());
		peopleList.add(p);
		
		runner.getGroup().setPeople(peopleList);
		
		runner.getGroup().getWagon().setPace((Paces) paceComboBox.getSelectedItem());
		runner.getGroup().setProfession((Professions) professionComboBox.getSelectedItem());
		runner.getGroup().setRation((Rations) foodRationsComboBox.getSelectedItem());
		runner.getGroup().updateMoney();
		
		System.out.println(runner.getGroup());
		System.out.println(runner.getGroup().getWagon());
	}
//	private class comboBoxListener implements ActionListener
//	{
//		public void actionPerformed(ActionEvent e)
//		{
////			runner.getGroup().getWagon().setPace(paceComboBox.getSelectedIndex()+1);
//			
//			System.out.println(runner.getGroup().getWagon().getPace() + " pace equals");
//		}
//	}
}